import Koa from "koa";
import body from "koa-body";
import Router from "koa-router"; // 引入koa-router
const app = new Koa();
const router = new Router(); // 创建路由，支持传递参数

app.use(
    body({
        urlencoded: true,
        multipart: true,
        formidable: {
            maxFieldsSize: 2 * 1024 * 1024, // 文件上传大小
        },
    })
);
app.use(router.routes());

const returnM = (ctx) => {
    let { query, headers, body, file, files } = ctx.request;
    console.log(query, body, file, files);
    ctx.response.body = { query, headers, body, file, files };
    ctx.response.type = "application/json";
};

router.get("/test", returnM).post("/test", returnM).put("/test", returnM);

app.listen(7438);
